﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SPSimpleDeveloper.DAL
{
    /// <summary>
    /// Reads files content for files place as embedded resource
    /// </summary>
    public class EmbeddedFilesHelper
    {
        /// <summary>
        /// Reads file content from embedded resources file
        /// </summary>
        /// <param name="assemblyFolderName">Should be "assembly.folder."</param>
        /// <param name="fileName">File name in solution</param>
        /// <returns>Content of the selected file; null if incorrect file path has been passed</returns>
        public string ReadFileContent(string assemblyFolderName, string fileName)
        {
            try
            {
                string result = string.Empty;

                using (Stream stream = this.GetType().Assembly.GetManifestResourceStream(assemblyFolderName + fileName))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        result = reader.ReadToEnd();
                    }
                }

                return result;
            }
            catch
            {
                return null; 
            } 
        }
    }
}
